import { Middleware } from '@reduxjs/toolkit';

export const persistMiddleware: Middleware = (store) => (next) => (action) => {
  const result = next(action);
  const state = store.getState();

  // 选择需要持久化的状态
  const persistedState = {
    auth: state.auth,
  };

  // 保存到 localStorage
  localStorage.setItem('appState', JSON.stringify(persistedState));

  return result;
};